package com.zjinyin.forum.exception;

import com.zjinyin.forum.common.AppResult;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DELL
 * Date: 2023-08-09
 * Time: 10:02
 */

/**
 * 自定义的异常 : 加入状态码与状态属性, 并提供接口给外部访问
 */
public class ApplicationException extends RuntimeException {

    // 定义为 protected 权限防止会继承其他包下的错误异常
    protected AppResult errorResult;

    // 构造方法
    public ApplicationException(AppResult errorResult) {
        super(errorResult.getMessage()); // 优先去获取打印的是枚举的错误信息 (ApplicationException ) 而非 RuntimeException
        this.errorResult = errorResult;
    }

    public ApplicationException(String message) {
        super(message);
    }

    public ApplicationException(String message, Throwable cause) {
        super(message, cause);
    }

    public ApplicationException(Throwable cause) {
        super(cause);
    }

    public AppResult getErrorResult() {
        return errorResult;
    }

    public void setErrorResult(AppResult errorResult) {
        this.errorResult = errorResult;
    }
}
